#!/usr/bin/python

import sqlite3
import time
import struct

sqlite_file = "/home/ubuntu/picsad.db"
conn = sqlite3.connect(sqlite_file)

file_name = "/home/ubuntu/umm_000000_29.bin"
f = open(file_name, "rb")

li_arr = []
while True:
    x_str = f.read(4)
    if x_str == b'':
        break
    y_str = f.read(4)
    z_str = f.read(4)
    intensity_str = f.read(4)
    x = struct.unpack('f', x_str)[0]
    y = struct.unpack('f', y_str)[0]
    z = struct.unpack('f', z_str)[0]
    intensity = struct.unpack('f', intensity_str)[0]
    li_arr.append((x, y, z, intensity))

f.close()

print(len(li_arr))
start = time.clock()
c = conn.cursor()
c.executemany("INSERT INTO point_cloud(x_axis, y_axis, z_axis, intensity) values (?, ?, ?, ?)", li_arr)
conn.commit()
conn.close()
end = time.clock()
print(end - start)
